//package com.tj.collection.controller;
//
//import com.google.auth.oauth2.GoogleCredentials;
//import com.google.cloud.storage.*;
//import com.google.common.collect.Lists;
//
//import java.io.*;
//import java.nio.charset.StandardCharsets;
//
//public class TestController {
//    private static final String credentialsStr = "{\n" +
//            "  \"type\": \"service_account\",\n" +
//            "  \"project_id\": \"meboo-online-b68e7\",\n" +
//            "  \"private_key_id\": \"319b81ac7aebc908864fef7f15feec8496814f41\",\n" +
//            "  \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCizdcMFhh0Y3hp\\nYu0oXw0x0k/Cj3hfP7IU2cmksaTOpLn3vdMW5uEbh2Yeov3NthWYZ4L0uogRm074\\nU9hat7HvbMpE5kkOmrnIIc3Yh/sHhNKHkXqiLXRksOuVxJG72ZH6eyAHKkb63wkP\\ngWqxF97n1xBrR2OqQr4pIl0aLP5bc0NSW+1xz4YViZbIFcO3y9L0Jv+2hpq1zG9w\\nkqvw4o5feholpcpm8+SPQjNR2JUy+4CEFkmriJFEaOYSnFjqRow8ZX7SAj/d+K1F\\n1TopGXcWC0lvzHebPxPnOCqyzyBobYA9u3vft64YFIakrXHYkpF/QfnRO8qKAMFZ\\nW2qZDcmFAgMBAAECggEAIxT0l2HmhKQPpTQAU1ACNZ9yeQQ2Bd5hpz0UBtWR5Eaa\\nXVCOHXQEg4xefNEWHH81cZkynr5YRmT/dCMLLudBJEz+3DB8gzVjvcTNCPEqbqEY\\nRcbbVHmziGQYa/ZHCiH04zMngGvDjllD6E+0uDMi4TYWj2t7hkuqEw6Y3eRerkFU\\n/XnyJi+T/gj5junnkH/Bf6xY3XE1H4GCoOnxHY8aUzD+oCHgC8Q9Ash6CVkhrpeu\\nUm+t2Y4JbBM7DB5IMt5bP8JGgFs3NLKd736Xx9Nxngh1wU8hqvIEQEyVoRYuzAZc\\nCFoiSMpCWGepycjO7x6n7FdZ3Aae/2XbqiPkrkd2oQKBgQDOq8d7M6fzDGQCInhb\\nQ9X/0NUYVC9bZA389xXV+beOKYtKWvA2Lhx1m4JaZxGB0jSrPpPS+9Up8hhDyrmT\\n7yKsRcKkMtQj/w8FQv3z1TvNVFdVh77cSeq900FwzCi0E53SMSDQhco08uy5+qv1\\nxihTrxSW3E/5Gcgir5c6ZHzsZQKBgQDJqah9BrZXu/4XyGEhVO8TrWrdV0Er5qY0\\nLlkjSbraZDvLCR4SQBiuvNUlUqUMyzESBgE0k27h4jCHLIoGg3GaZbh2MYhPTxMo\\nF8lhLQBKw8y+8BJyeH6zdKdlt/myuIlTiQFQOwrQhVgNGVVn+E0CnRWvkxMAB6/+\\nBJjoZRvGoQKBgHkDMGy9VGwGJ1DwqhSWZenCd+Qk9w3GSkKC0zBVZdtCDCNfmCPB\\nYDyk7/DLRP8E/H4AyEHT338OGJMpUvyCG4VP26aVdI4XPM5R6a0qgDe8WN7l+yW1\\nylOYLUtE39iBW/nFdndiv4G9dEt5sdLZUqedbqrfGZy8MenNcvln+ZXZAoGAMJGT\\n6si7EdZNFB1Gh2iVS//wRO7G23Ppg5fGECGpxv9tBzFi9LJLP4prK1oENliZsOWR\\nVMBNbEm1tlibxYXSzoTBMHYthixdSMKx1Z2o/Fi77yCS0M8EdOQbjPwKP2kCagQN\\nNO2DZUU4N69qSmga5A5BMtARO2iekmc5DH+NeQECgYB3GODbjx4+pn36N37X48pi\\ntHQBlq9ETUCRDK8MnvaMBO+1qECR6ga7jTnM4jVcE3HQ1KPuWNwADBYMzXnmhlsp\\nqX+ylzHGwy+XFrP1l0okCaBzTcUxNENoo7pi31bLby5qG7GEwWpP2cxCTauQO9HM\\nbQrwhNI1Cr4N2ZZhzmnVPA==\\n-----END PRIVATE KEY-----\\n\",\n" +
//            "  \"client_email\": \"storage-for-meboo@meboo-online-b68e7.iam.gserviceaccount.com\",\n" +
//            "  \"client_id\": \"114277768109913048775\",\n" +
//            "  \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n" +
//            "  \"token_uri\": \"https://oauth2.googleapis.com/token\",\n" +
//            "  \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n" +
//            "  \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/storage-for-meboo%40meboo-online-b68e7.iam.gserviceaccount.com\",\n" +
//            "  \"universe_domain\": \"googleapis.com\"\n" +
//            "}";
//
//    private static final String projectId = "meboo-online-b68e7";
//    private static final String bucketName = "meboo-online-b68e7.appspot.com";
//
//    public static void main(String[] args) {
//        try {
//
//            FileInputStream fin = new FileInputStream("/Users/yujianfu/Desktop/forgooglecloud.webp");
//            String s = uploadImage("taaata.webp", "/Users/yujianfu/Desktop/forgooglecloud.webp", "image/webp");
//
//            System.err.println(s);
//
////            GoogleCredentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(credentialsStr.getBytes()))
////                    .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
////
////            Storage storage = StorageOptions.newBuilder().setProjectId(projectId).setCredentials(credentials).build().getService();
////
//////        Storage storage = StorageOptions.getDefaultInstance().getService();
////
////            BlobInfo blobInfo = BlobInfo.newBuilder("", "aa.webp")
////                    .setContentType("image/webp")
////                    .build();
////
////            FileInputStream fin = new FileInputStream("/Users/yujianfu/Desktop/forgooglecloud.webp");
////            ByteArrayOutputStream bou = new ByteArrayOutputStream();
////            int x = 0;
////            while ((x = fin.read()) != -1) {
////                bou.write(x);
////            }
////
////            Blob blob = storage.create(blobInfo, bou.toByteArray());
////            boolean isImageUploaded = blob.exists();
//
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
//
//
//    public static void uploadObjectFromMemory(
//            String projectId, String bucketName, String objectName, String contents) throws IOException {
//        // The ID of your GCP project
//        // String projectId = "your-project-id";
//
//        // The ID of your GCS bucket
//        // String bucketName = "your-unique-bucket-name";
//
//        // The ID of your GCS object
//        // String objectName = "your-object-name";
//
//        // The string of contents you wish to upload
//        // String contents = "Hello world!";
//
//        Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
//        BlobId blobId = BlobId.of(bucketName, objectName);
//        BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
//        byte[] content = contents.getBytes(StandardCharsets.UTF_8);
//        storage.createFrom(blobInfo, new ByteArrayInputStream(content));
//
//        System.out.println(
//                "Object "
//                        + objectName
//                        + " uploaded to bucket "
//                        + bucketName
//                        + " with contents "
//                        + contents);
//    }
//
//    public static String uploadImage(String fileName , String filePath,String fileType) throws IOException {
//        Bucket bucket = getBucket(bucketName);
//        InputStream inputStream = new FileInputStream(new File(filePath));
//        Blob blob = bucket.create(fileName, inputStream, fileType);
//        System.err.println("Blob Link:"+blob.getMediaLink());
//        return blob.getMediaLink();
//    }
//
//
//    private static Bucket getBucket(String bucketName) throws IOException {
//        GoogleCredentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(credentialsStr.getBytes()))
//                .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
//        Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
//        Bucket bucket = storage.get(bucketName);
//        if (bucket == null) {
//            throw new IOException("Bucket not found:"+bucketName);
//        }
//        return bucket;
//    }
//
//}
